package chapters15_bingfa.chapters15_3;

/**
 * Created by xinxuchu on 2020/1/27.
 */
public class WaitThread extends Thread {


    private volatile boolean fire = false;

    @Override
    public void run(){
        try {
            //synchronized修饰代码块
            synchronized (this){
                while (!fire){
                    wait();
                }
            }
            System.out.println("fired");
        }catch (InterruptedException e){
        }
    }

    public synchronized void fire(){
        this.fire = true;
        notify();
    }

    public static void main(String[] args) throws InterruptedException {
        WaitThread waitThread = new WaitThread();
        waitThread.start();
        Thread.sleep(1000);
        System.out.println("fire");
        waitThread.fire();
    }
}
